import { Module } from 'vuex';
import {ReportData, RootStateTypes} from '/@/store/interface/index';

const reportModule: Module<ReportData, RootStateTypes> = {
    namespaced: true,
    state: {
        currentReport: sessionStorage.getItem('currentReport') ? JSON.parse(sessionStorage.getItem('currentReport')!) : {},
    },
    mutations: {
        setCurrentReport(state, newData) {
            if(newData){
                state.currentReport = newData;
            }
        },
    },
    actions: {
        // 设置报告期
        async setCurrentReport({ commit }, data: object) {
            if (data) {
                commit('setCurrentReport', data);
                sessionStorage.setItem('currentReport', JSON.stringify(data));
                console.log('插入当前报告期成功');
            }
        },
    },
};

export default reportModule;
